# -*- coding: utf-8 -*-

from pylab import *

f=open("lbh_chopped.txt",'r')
all=f.readlines()
f.close()

lat=[];lon=[];hei=[]

for line in all:
    line=line.split(" ")
    lat.append(float(line[0]))
    lon.append(float(line[1]))
    hei.append(float(line[2]))

#latitude(deg) longitude(deg)  height(m)
'''
print "lat="+repr(lat)+"\n\n"

print "lon="+repr(lon)+"\n\n"

print "hei="+repr(hei)+"\n\n"
'''
###############################################
f=open("xyz_chopped.txt",'r')
all=f.readlines()
f.close()

x=[];y=[];z=[]

for line in all:
    line=line.split(" ")
    x.append(float(line[0]))
    y.append(float(line[1]))
    z.append(float(line[2]))


#latitude(deg) longitude(deg)  height(m)
'''
print "x="+repr(x)+"\n\n"

print "y="+repr(y)+"\n\n"

print "z="+repr(z)+"\n\n"
'''
################################################
f=open("enu_chopped.txt",'r')
all=f.readlines()
f.close()

e=[];n=[];u=[]

for line in all:
    line=line.split(" ")
    e.append(float(line[0]))
    n.append(float(line[1]))
    u.append(float(line[2]))

#latitude(deg) longitude(deg)  height(m)
'''
print "e="+repr(e)+"\n\n"

print "n="+repr(n)+"\n\n"

print "u="+repr(u)
'''
################################################
plot(e,n,'.');axis("equal")
E,N=mean(e),mean(n)
plot(E,N,'^r')
################################################
d=((array(e)-E)**2+(array(n)-N)**2)**0.5
d.sort()
r1=d[int(size(d)*0.5)]
r2=d[int(size(d)*0.667)]
plt.title("cep=%fm, rms=%fm, mean(e,n)=(%f,%f)" %(r1,r2,E,N))
################################################
theta = np.linspace(0,2*pi,72)
x1 = r1*cos(theta)+E
y1 = r1*sin(theta)+N
plot(x1,y1,'r')

x2 = r2*cos(theta)+E
y2 = r2*sin(theta)+N
plot(x2,y2,'r')